<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" type="image/svg+xml" href="/razorconsole-icon.svg" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>RazorConsole - Build Rich Console Apps with Razor</title>
    <script>
    // Prevent FOUC: apply only "dark" class before React loads.
    (function () {
      try {
        const theme = localStorage.getItem('theme') // "light" | "dark" | "system" | null
        const root = document.documentElement

        if (theme === 'dark') {
          root.classList.add('dark')
        } else if (theme === 'light') {
          // ensure no 'dark' class - doing nothing is fine if markup starts without it
          root.classList.remove('dark')
        } else {
          // system preference: add `dark` only if system is dark
          if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
            root.classList.add('dark')
          }
        }
      } catch (e) {
        // ignore (e.g. localStorage not available)
      }
    })()
    </script>
  </head>
  <body>
    <div id="root"></div>
    <script type="module" src="/src/main.tsx"></script>
    <!-- GitHub Pages SPA redirect script -->
    <script type="text/javascript">
      // Single Page Apps for GitHub Pages
      // MIT License
      // https://github.com/rafgraph/spa-github-pages
      // This script checks to see if a redirect is present in the query string,
      // converts it back into the correct url and adds it to the
      // browser's history using window.history.replaceState(...),
      // which won't cause the browser to attempt to load the new url.
      // When the single page app is loaded further down in this file,
      // the correct url will be waiting in the browser's history for
      // the single page app to route accordingly.
      (function (l) {
        // Log the initial window.location
        if (l.search[1] === "/") {
          var decoded = l.search
            .slice(1)
            .split("&")
            .map(function (s) {
              return s.replace(/~and~/g, "&");
            })
            .join("?");

          var finalUrl = l.pathname.slice(0, -1) + decoded + l.hash;

          // Log the final replaced location
          console.log("Final replaced location:", {
            original: l.href,
            decoded: decoded,
            finalUrl: finalUrl,
          });

          window.history.replaceState(null, null, finalUrl);
        } else {
          console.log(
            'No redirect needed - search parameter does not start with "/"'
          );
        }
      })(window.location);
    </script>
  </body>
</html>
